<template>
	<view class="works">
		<textarea maxlength='-1' v-model="content" class="textarea" placeholder-style="color:#ccc" placeholder="做首诗吧!"/>
		<view class="tijiao" @click="tijiao">
			<span>提交</span>
		</view>
	</view>
	
</template>

<script>
	export default{
		data(){
			return{
				content:'',
				userInfo:{}
			}
		},
		onLoad() {
			
			this.userInfo = uni.getStorageSync('user');
			
		},
		methods:{
			tijiao(){
				
				if(this.userInfo.name==""&&!this.userInfo.name){
					uni.showToast({
						title:"请先登陆",
						icon:'none'
					})
					uni.navigateTo({
						url:"/pages/login/login"
					})
					return
				}
				if(!this.content){
					uni.showToast({
						title:"内容不能为空",
						icon:'none'
					})
					return
				}
				this.$api.textadd({content:this.content,name:this.userInfo.name}).then(res=>{
					if(res.code==200){
						uni.showToast({
							title:res.message,
							icon:'none'
						})
						uni.navigateTo({
							url:"/pages/work/mywork/mywork"
						})
						
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.works{
		width: 100%;
		padding-top: 15px;
		.textarea{
			border-radius: 20px;
			width: 90%;
			margin-top: 20px;
			border: 1px solid #ccc;
			padding: 10px;
			margin: auto;
		}
		.tijiao{
			width: 50%;
			margin: auto;
			height: 40px;
			text-align: center;
			line-height: 40px;
			color: #fff;
			background: #596687;
			margin-top: 50px;
			border-radius: 10px;
		}
	}
	
	
</style>